//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.WebControls;
using CommunityServer.ControlPanel.Controls;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Controls;
using CommunityServer.Components;
using CommunityServer.Galleries.Components;
using ResourceControl = CommunityServer.ControlPanel.Controls.ResourceControl;

namespace CommunityServer.ControlPanel.Photos
{
	/// <summary>
	/// Summary description for GalleryEditorHomePage.
	/// </summary>
	public class GalleryEditorHomePage : BaseGalleryPage
	{

		#region Child Controls

		protected ControlPanelSelectedNavigation SelectedNavigation1;
		protected ResourceControl Resourcecontrol1;
		protected MPContent DescriptionRegion;
		protected Label Owners;
		protected Label DateCreated;
		protected ResourceControl ResourceControl3;
		protected ResourceControl Resourcecontrol5;
		protected Label PostCount;
		protected Label DiskUsage;
		protected Label PostLimit;
		protected Label DiskLimit;
		protected ResourceControl Resourcecontrol6;
		protected Label PostRecentTitle;
		protected Label PostRecentAuthor;
		protected Label PostRecentDate;
		protected ResourceControl Resourcecontrol4;
		protected ResourceControl Resourcecontrol2;
		protected Label CommentCount;
		protected Label TrackbackCount;
		protected MPContent TaskRegion;
		protected Label SectionName;
		protected ResourceControl Resourcecontrol8;
		protected ResourceControl Resourcecontrol7;
		protected ResourceControl Resourcecontrol9;
		protected ResourceControl Resourcecontrol10;
		protected ResourceControl Resourcecontrol11;
		protected ResourceControl Resourcecontrol12;
		protected ResourceControl Resourcecontrol13;
		protected Panel RecentPostInfo;
		protected ResourceControl NoRecentPost;
		protected MPContainer MPContainer;

		#endregion
	
		private void Page_Load(object sender, EventArgs e)
		{
			CSContext cntx = CSContext.Current;
			SectionName.Text = CurrentGallery.Name;
			PostCount.Text = CurrentGallery.PostCount.ToString();
			TrackbackCount.Text = CurrentGallery.TrackbackCount.ToString();
			CommentCount.Text = CurrentGallery.CommentCount.ToString();
			DateCreated.Text = CurrentGallery.DateCreated.ToString(cntx.User.Profile.DateFormat);
			PostRecentAuthor.Text = CurrentGallery.MostRecentPostAuthor;
			PostRecentDate.Text = CurrentGallery.MostRecentPostDate.ToString(cntx.User.Profile.DateFormat);
			PostRecentTitle.Text = CurrentGallery.MostRecentPostSubject;
			Owners.Text = CurrentGallery.Owners;
			DiskUsage.Text = FormatByteCount(CurrentGallery.DiskUsage);
			DiskLimit.Text = FormatByteCount(CurrentGallery.GetActiveQuota(GalleryQuotaType.Disk));
			if(DiskLimit.Text != "-1" && DiskLimit.Text.Length > 0)
			{
				DiskLimit.Text = " / " + DiskLimit.Text;
			}
			else
			{
				DiskLimit.Text = "";
			}
			PostLimit.Text = CurrentGallery.GetActiveQuota(GalleryQuotaType.Image).ToString();
			if(PostLimit.Text != "-1"  && PostLimit.Text.Length > 0)
			{
				PostLimit.Text = " / " + PostLimit.Text;
			}
			else
			{
				PostLimit.Text = "";
			}

			RecentPostInfo.Visible = (CurrentGallery.PostCount > 0);
			NoRecentPost.Visible = (CurrentGallery.PostCount == 0);

		}

		private string FormatByteCount(Int64 byteCount)
		{
			const string cpResourceFile = "ControlPanelResources.xml";
			string formattedCount = String.Empty;

			if(byteCount >= (Int64)DataUnit.GigaByte)
			{
				formattedCount = String.Format("{0:#,###.##}",((double)byteCount / (Int64)DataUnit.GigaByte)) + ResourceManager.GetString("CP_Gigabytes", cpResourceFile);
			}
			else if(byteCount >= (Int64)DataUnit.MegaByte)
			{
				formattedCount = String.Format("{0:#,###.##}",((double)byteCount / (Int64)DataUnit.MegaByte)) + ResourceManager.GetString("CP_Megabytes", cpResourceFile);
			}
			else if(byteCount >= (Int64)DataUnit.KiloByte)
			{
				formattedCount = String.Format("{0:#,###.##}",((double)byteCount / (Int64)DataUnit.KiloByte)) + ResourceManager.GetString("CP_Kilobytes", cpResourceFile);
			}
			else if(byteCount >= 0)
			{
				string formattedBytes = String.Format("{0:#,###}",byteCount);
				if (formattedBytes.Length == 0)
					formattedBytes = byteCount.ToString();

				formattedCount = formattedBytes + ResourceManager.GetString("CP_Bytes", cpResourceFile);
			}

			return formattedCount;
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new EventHandler(this.Page_Load);

		}
		#endregion
	}
}
